package com.castle.fortress.admin.study.exam.rest;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.castle.fortress.admin.core.constants.GlobalConstants;
import com.castle.fortress.admin.study.exam.dto.StudyQuestionDto;
import com.castle.fortress.admin.study.exam.entity.StudyQuestionbankEntity;
import com.castle.fortress.admin.study.exam.dto.StudyQuestionbankDto;
import com.castle.fortress.admin.system.entity.SysUser;
import com.castle.fortress.admin.study.exam.service.StudyQuestionbankService;
import com.castle.fortress.common.utils.ConvertUtil;
import com.castle.fortress.admin.utils.WebUtil;
import com.castle.fortress.common.entity.RespBody;
import com.castle.fortress.common.exception.BizException;
import com.castle.fortress.common.respcode.GlobalRespCode;
import com.castle.fortress.common.enums.OperationTypeEnum;
import com.castle.fortress.admin.core.annotation.CastleLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.util.Strings;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 题库管理 api 控制器
 *
 * @author castle
 * @since 2023-02-09
 */
@Api(tags="题库管理api管理控制器")
@RestController
@RequestMapping("/api/study/exam/studyQuestionbank")
public class ApiStudyQuestionbankController {
    @Autowired
    private StudyQuestionbankService studyQuestionbankService;


    /**
     * 开放学习的题库管理的分页展示
     * @param studyQuestionbankDto 题库管理实体类
     * @param currentPage 当前页
     * @param size  每页记录数
     * @return
     */
    @CastleLog(operLocation="题库管理-api",operType = OperationTypeEnum.QUERY)
    @ApiOperation("开放学习的题库分页展示")
    @GetMapping("/page")
    public RespBody<IPage<StudyQuestionbankDto>> pageStudyQuestionbank(StudyQuestionbankDto studyQuestionbankDto, @RequestParam(required = false) Integer currentPage, @RequestParam(required = false)Integer size){
        Integer pageIndex= currentPage==null? GlobalConstants.DEFAULT_PAGE_INDEX:currentPage;
        Integer pageSize= size==null? GlobalConstants.DEFAULT_PAGE_SIZE:size;
        Page<StudyQuestionbankDto> page = new Page(pageIndex, pageSize);

        IPage<StudyQuestionbankDto> pages = studyQuestionbankService.pageOpenStudyQuestionbank(page, studyQuestionbankDto);
        return RespBody.data(pages);
    }

//    /**
//     * 题库管理保存
//     * @param studyQuestionbankDto 题库管理实体类
//     * @return
//     */
//    @CastleLog(operLocation="题库管理-api",operType = OperationTypeEnum.INSERT)
//    @ApiOperation("题库管理保存")
//    @PostMapping("/save")
//    public RespBody<String> saveStudyQuestionbank(@RequestBody StudyQuestionbankDto studyQuestionbankDto){
//        if(studyQuestionbankDto == null ){
//            throw new BizException(GlobalRespCode.PARAM_MISSED);
//        }
//            StudyQuestionbankEntity studyQuestionbankEntity = ConvertUtil.transformObj(studyQuestionbankDto,StudyQuestionbankEntity.class);
//        if(studyQuestionbankService.save(studyQuestionbankEntity)){
//            return RespBody.data("保存成功");
//        }else{
//            return RespBody.fail(GlobalRespCode.OPERATE_ERROR);
//        }
//    }
//
//    /**
//     * 题库管理编辑
//     * @param studyQuestionbankDto 题库管理实体类
//     * @return
//     */
//    @CastleLog(operLocation="题库管理-api",operType = OperationTypeEnum.UPDATE)
//    @ApiOperation("题库管理编辑")
//    @PostMapping("/edit")
//    public RespBody<String> updateStudyQuestionbank(@RequestBody StudyQuestionbankDto studyQuestionbankDto){
//        if(studyQuestionbankDto == null || studyQuestionbankDto.getId() == null || studyQuestionbankDto.getId().equals(0L)){
//            throw new BizException(GlobalRespCode.PARAM_MISSED);
//        }
//            StudyQuestionbankEntity studyQuestionbankEntity = ConvertUtil.transformObj(studyQuestionbankDto,StudyQuestionbankEntity.class);
//        if(studyQuestionbankService.updateById(studyQuestionbankEntity)){
//            return RespBody.data("保存成功");
//        }else{
//            return RespBody.fail(GlobalRespCode.OPERATE_ERROR);
//        }
//    }
//
//    /**
//     * 题库管理删除
//     * @param ids 题库管理id集合
//     * @return
//     */
//    @CastleLog(operLocation="题库管理-api",operType = OperationTypeEnum.DELETE)
//    @ApiOperation("题库管理删除")
//    @PostMapping("/delete")
//    public RespBody<String> deleteStudyQuestionbank(@RequestBody List<Long> ids){
//        if(ids == null || ids.isEmpty()){
//            throw new BizException(GlobalRespCode.PARAM_MISSED);
//        }
//        if(studyQuestionbankService.removeByIds(ids)) {
//            return RespBody.data("保存成功");
//        }else{
//            return RespBody.fail(GlobalRespCode.OPERATE_ERROR);
//        }
//    }
//
//    /**
//     * 题库管理详情
//     * @param id 题库管理id
//     * @return
//     */
//    @CastleLog(operLocation="题库管理-api",operType = OperationTypeEnum.QUERY)
//    @ApiOperation("题库管理详情")
//    @GetMapping("/info")
//    public RespBody<StudyQuestionbankDto> infoStudyQuestionbank(@RequestParam Long id){
//        if(id == null){
//            throw new BizException(GlobalRespCode.PARAM_MISSED);
//        }
//            StudyQuestionbankEntity studyQuestionbankEntity = studyQuestionbankService.getById(id);
//            StudyQuestionbankDto studyQuestionbankDto = ConvertUtil.transformObj(studyQuestionbankEntity,StudyQuestionbankDto.class);
//        return RespBody.data(studyQuestionbankDto);
//    }


}
